using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

namespace DOJ.LEISP.LEXS.Common.Providers
{
    public class DefaultSructuredSearchProvider : IStructuredSearchProvider
    {
        public List<SearchResultPackageType> DoStructuredSearch(List<StructuredQueryType> structuredQuery, int maxItemMatches, List<DataCategoryCodeType> dataCategory, out ResultCodeSimpleType resultCode, out SearchResponseMetadataType searchResponseMetadata)
        {
            ///This method is mocked up to return a default response.  In the real world you would loop through the structured queries and query your data source
            ///i.e., your database, xml repository, or another service.

            ///Logic to perform query against data source would go here.
            List<SearchResultPackageType> results = new List<SearchResultPackageType>();

            XDocument resultDocument = XDocument.Load(String.Format("{0}{1}",ConfigurationManager.AppSettings.Get("DataDirectory"),@"StructuredSearchResults-3.xml"));
            SearchResponseMessageType xmlRoot = Utilities.XmlSerializerUtility.Deserialize<SearchResponseMessageType>(resultDocument.ToString());

            results.AddRange(xmlRoot.SearchResultPackage.ToList());

            searchResponseMetadata = new SearchResponseMetadataType();
            searchResponseMetadata.StructuredQueryMatchScore = "100";
            searchResponseMetadata.MaxItemMatchesRequested = maxItemMatches;
            searchResponseMetadata.NumberItemMatches = results.Count.ToString();
            searchResponseMetadata.ServerLimitIndicator = false;

            resultCode = ResultCodeSimpleType.Success;
            return results;
        }
    }
}
